import { getMyData, getTeamData, getActivity } from '@/gql/earthPushing/user';
import { toPublish } from '@mqtt';
import { defineStore } from 'pinia';
import { getDriverID } from '@/stores/driverID';
import { showLoading } from '@/utils/prompt';
export const DataStore = defineStore('data', {
	state: () => ({
		informationMine: {},
		informationGroup: {},
		informationMovable: {},
	}),
	getters: {},
	actions: {
		// 获取我的数据
		informationMY(value: string) {
			if (!getDriverID()) {
				return
			}
			showLoading()
			const payload = {
				query: getMyData,
				variables: { staff_id: getDriverID(), type: value },
			};
			toPublish(
				'ql/staff/getMyData',
				payload,
				(obj: any) => {
					uni.hideLoading()
					const { getMyData } = obj.data;
					this.informationMine = getMyData
				},
			);
		},
		//获取团队数据
		informationTeam(value: string) {
			if (!getDriverID()) {
				return
			}
			showLoading()
			const payload = {
				query: getTeamData,
				variables: { staff_id: getDriverID(), type: value },
			};
			toPublish(
				'ql/staff/getTeamData',
				payload,
				(obj: any) => {
					uni.hideLoading()
					const { getTeamData } = obj.data;
					this.informationGroup = getTeamData
				},
			);
		},
		//获取活动数据
		informationActive() {
			if (!getDriverID()) {
				return
			}
			showLoading()
			const payload = {
				query: getActivity,
			};
			toPublish(
				'ql/staff/getActivity',
				payload,
				(obj: any) => {
					uni.hideLoading()
					const { getActivity } = obj.data;
					this.informationMovable = getActivity
				},
			);
		},
	},
});